<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 17-7-18
 * Time: 上午11:30
 */

namespace ActionsHttp;

use Data\Order_form_DAO;
use Data\Order_for_foods_DAO;

class ConsumerRetreatOrderForm extends BaseActionHttp
{
    public function doAction() {
        parent::doAction();
        // 订单id
        $order_form_id = $this->data[ORDER_FORM_ID];
        $order_form_record = Order_form_DAO::getRecord($order_form_id);
        if (!$order_form_record) {
            return $this->SendErrMsg("错误，没有此订单信息");
        }
        // 订单发起人
        $created_by = $order_form_record->getCREATED_BY();
//        if ($created_by != $_SESSION[CONSUMER_ID]) {
//            return $this->SendErrMsg("退单失败");
//        }

        // 是否已付款
        $order_form_pay_status = $order_form_record->getPAY_STATUS();
        if($order_form_pay_status!=PAY_STATUS_YES) {
            return $this->SendErrMsg("订单未付款，不能退单");
        }
        if ($order_form_record->getIS_ENTRY() == STATE_YES) {
            return $this->SendErrMsg("该订单已入帐，不能退单");
        }
        if ($order_form_record->getRETREAT_ORDER_STATUS() == RETREAT_ORDER_STATUS_START) {
            return $this->SendErrMsg("已发起过退单申请，正在进行中");
        }
        if ($order_form_record->getRETREAT_ORDER_STATUS() == RETREAT_ORDER_STATUS_SUC) {
            return $this->SendErrMsg("已退单，不能再次退单");
        }
        if ($order_form_record->getRETREAT_FOOD_STATUS() == RETREAT_FOOD_STATUS_START) {
            return $this->SendErrMsg("退单失败，已发起的退菜申请正在进行中");
        }
        // 是否成功退过菜
        $order_for_food_list = Order_for_foods_DAO::getRetreatList($order_form_id);
        if ($order_for_food_list) {
            return $this->SendErrMsg("已退过菜，不能进行退单操作");
        }


        $order_form_record->setRETREAT_ORDER_STATUS(RETREAT_ORDER_STATUS_START);
        Order_form_DAO::update($order_form_record);

        $this->ResponseDataToCurrentClient();
    }
}